package com.example.base.system.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.base.security.IsSecurity;
import com.example.base.utils.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@RestController
@RequestMapping("/upload")
public class SysFileController {

    @IsSecurity(isSecurity = false)
    @PostMapping("file")
    public JSONObject uploadFile(@RequestParam("file")MultipartFile file) throws IOException {
        if(file==null){
            return Result.errorInfo("上传的文件不得为空");
        }
        System.out.println(file.getName());
        file.transferTo(new File("D:\\upload\\"+ file.getOriginalFilename()));
        return Result.successInfo("文件上传成功");
    }


}
